<template>
  <div>
    <ul class="songList">
      <p class="pr">搜索结果</p>
      <li v-for="item in songs" :key="item.id">
        <!-- <i v-show="showNum" :class="['num', { red: index < 3 }]">
          {{ (index + 1) | addZero }}
        </i> -->
        <div class="left">
          <h5 v-html="$options.filters.hightLight(item.name,keywords)"></h5>
          <p>
            <i
              v-show="
                item.song &&
                item.song.privilege &&
                item.song.privilege.playMaxbr == 999000
              "
              class="sq"
            ></i>
            <span v-if="item.artists"></span>{{ item.artists[0].name }}
          </p>
        </div>
        <div class="right">
          <a class="playBtn" 
             href="javaScript:void(0)"
             @click="$emit('play',item)">
          </a>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "SearchResult",
  props: ["keywords"],
  data() {
    return {
      songs: [],
    };
  },
  methods: {},
  filters: {
    addZero(val) {
      return val < 10 ? "0" + val : val;
    },
    hightLight(value,keywords){
        return String(value).replace(keywords,'<span style="color:red">'+keywords+'</span>')
    }
  },
  created() {
    this.$http
      .get("search", {
        params: {
          keywords: this.keywords,
        },
      })
      .then((d) => {
        //   console.log(d);
        if(!d.data.result.songs) return;
        this.songs = d.data.result.songs;
      });
  },
};
</script>
<style lang="less" scoped>
.songList {
     padding: 15px 10px 0;
  p.pr {
    margin-left: 8px;
    font-size: 12px;
    line-height: 12px;
    color: #666;
  }
  background-color: #fff;
  padding: 5px 10px;
  li {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    i.num {
      display: inline-block;
      width: 40px;
      font-size: 17px;
      line-height: 43px;
      font-style: normal;
    }
    i.red {
      color: #df3436;
    }
    .left {
      flex: 1;
      h5 {
        font-size: 17px;
        font-weight: 400;
      }
      p {
        font-size: 12px;
        color: #888;
        i.sq {
          display: inline-block;
          width: 13px;
          height: 12px;
          background: url(../assets/index_icon_2x.png) no-repeat;
          background-position: 0 0;
          background-size: 166px 97px;
          vertical-align: middle;
        }
      }
    }
    .right {
      width: 22px;
      height: 22px;
      .playBtn {
        display: inline-block;
        width: 22px;
        height: 22px;
        background: url(../assets/index_icon_2x.png) no-repeat;
        background-position: -24px 0;
        background-size: 166px 97px;
      }
    }
  }
}
</style>s